<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>3_回调ref中回调执行次数的问题</title>
    <!-- 引入 react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入 react-dom 用于支持操作DOM -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!-- 引入 babel 用于将 jsx转为 js -->
    <script type="text/javascript" src="../js/babel.min.js"></script>
</head>
<body>
<div id="test"></div>
<script type="text/babel">
    class Demo extends React.Component {
        state = {
            isHot: false
        }
        showInfo = () => {
            const {input1} = this;
            alert(input1.value);
        }

        changeWeather = () => {
            const {isHot} = this.state;
            this.setState({isHot:!isHot});
        }

        // 定义成类绑定的回调函数
        saveInput = (c) => {
            this.input1 = c;
            console.log("@", c);
        }

        render() {
            const {isHot} = this.state;
            return (
                <div>
                    <h1>今天天气很{isHot ? "炎热" : "凉爽"}</h1>
                    {/* 内联形式 */}
                    {/*<input ref={(curNode) => {this.input1 = curNode; console.log("@", curNode) }} type="text" placeholder="点击按钮提示数据" /> */}
                    <input ref={this.saveInput} type="text" placeholder="点击按钮提示数据" />
                    <button onClick={this.showInfo} >点我提示输入的数据</button> <br/><br/>
                    <button onClick={this.changeWeather}>点我切换天气</button>
                </div>
            )
        }
    }

    ReactDOM.render(<Demo />, document.getElementById("test"));
</script>
</body>
</html>